import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/layout/index.vue'

// 公共路由
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index.vue'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error/404.vue'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index.vue'),
        name: 'Dashboard',
        meta: { title: '控制台', icon: 'Monitor' }
      }
    ]
  }
]

// 动态路由
export const asyncRoutes = [
  {
    path: '/demo',
    component: Layout,
    meta: { title: '功能演示', icon: 'Menu', roles: ['admin'] },
    children: [
      {
        path: 'throttle',
        component: () => import('@/views/demo/throttle.vue'),
        name: 'Throttle',
        meta: { title: '防抖节流', icon: 'Timer' }
      },
      {
        path: 'flexible',
        component: () => import('@/views/demo/flexible.vue'),
        name: 'Flexible',
        meta: { title: '屏幕自适应', icon: 'Expand' }
      },
      {
        path: 'request',
        component: () => import('@/views/demo/request.vue'),
        name: 'Request',
        meta: { title: '请求封装', icon: 'Connection' }
      }
    ]
  },
  // 404 页面必须放在末尾
  { path: '/:pathMatch(.*)*', redirect: '/404', hidden: true }
]

const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes
})

export default router 